<?php
/*********************************************************
author			Henson
date			2011-3-30
function		生成网站地图
*********************************************************/
$rootpath = dirname(dirname(__FILE__));
include_once($rootpath."/common.inc.php");
include_once( _INC_PATH."database.php" );
$db = new database();
$pageview = intval(_FORVIEWNUM);//前台页面每页展示记录数
$common_urls = array(
	'http://www.87dianping.com/',
	'http://www.87dianping.com/login.php',
	'http://www.87dianping.com/regist.php',
	'http://www.87dianping.com/addestimate.php',
	'http://www.87dianping.com/add_cor.php',
	'http://www.87dianping.com/contact.php',
	'http://www.87dianping.com/suggest.php'
);
$date = date("Y-m-d");
$xml = '<?xml version="1.0" encoding="utf-8"?><urlset>';
foreach($common_urls as $url)
{
	$xml .= '<url><loc>'.$url.'</loc><lastmod>'.$date.'</lastmod><changefreq>daily</changefreq><priority>0.9</priority></url>';
}

//分类category
$xml .= '<url><loc>http://www.87dianping.com/category/</loc><lastmod>'.$date.'</lastmod><changefreq>daily</changefreq><priority>0.9</priority></url>';
$sql = "select id from tbl_cate_sub where fcid=1 and del_flg='0'";
$db->setQuery($sql);
$cate_ids = $db->loadResultList();
array_push($cate_ids, '99');
$cor_scale_arr['99'] = '';
$cor_type_arr['99'] = '';
foreach($cate_ids as $cateid)
{
	foreach($cor_scale_arr as $scaleid=>$scale_v)
	{
		foreach($cor_type_arr as $typeid=>$type_v)
		{
			$where  = " where del_flg='0'";
			if($cateid != '99'){
				$cateid_sql = ','.$cateid.',';
				$where .= " and concat(concat(',',ccid),',') like '%".$cateid_sql."%'";
			}
			if($scaleid != '99'){
				$where .= " and scale in ('".$scaleid."')";
			}
			if($typeid != '99'){
				$where .= " and type in ('".$typeid."')";
			}
			$sql = "select count(*) as total from tbl_corporation $where ";
			$total = $db->loadResult($sql);
			$total_page = ceil($total / $pageview)+1;
			for($i=1; $i<=$total_page; $i++)
			{
				$xml .= "<url><loc>http://www.87dianping.com/category/{$cateid}_{$scaleid}_{$typeid}_{$i}</loc><lastmod>$date</lastmod><changefreq>daily</changefreq><priority>0.9</priority></url>";
			}
		}
	}
}

//企业corporation
$xml .= '<url><loc>http://www.87dianping.com/corporation/</loc><lastmod>'.$date.'</lastmod><changefreq>daily</changefreq><priority>0.9</priority></url>';
$sql = "select id from tbl_corporation where del_flg='0'";
$db->setQuery($sql);
$cor_ids = $db->loadResultList();
foreach($cor_ids as $id)
{
	$xml .= "<url><loc>http://www.87dianping.com/corporation/{$id}/</loc><lastmod>$date</lastmod><changefreq>daily</changefreq><priority>0.9</priority></url>";
	$xml .= "<url><loc>http://www.87dianping.com/corporation/{$id}/profile.html</loc><lastmod>$date</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>";
	$xml .= "<url><loc>http://www.87dianping.com/corporation/{$id}/comment_1.html</loc><lastmod>$date</lastmod><changefreq>daily</changefreq><priority>0.8</priority></url>";
}

//教程tech
$xml .= "<url><loc>http://www.87dianping.com/tech/</loc><lastmod>$date</lastmod><changefreq>daily</changefreq><priority>0.9</priority></url>";
$sql = "select id from tbl_tech where del_flg='0' and published='1'";
$db->setQuery($sql);
$tech_ids = $db->loadResultList();
foreach($tech_ids as $tech_id)
{
	$xml .= "<url><loc>http://www.87dianping.com/tech/{$tech_id}.html</loc><lastmod>$date</lastmod><changefreq>daily</changefreq><priority>0.8</priority></url>";
}

$xml .= '</urlset>';

writeFile($xml, _ROOT.'/sitemap.xml');
echo 'finish';
die;
